<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="whf.framework.web.Constants"%>

<%@taglib uri="/WEB-INF/tlds/framework.tld" prefix="framework"%>
<%@taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/common/inc/select.jsp" %>
</head>
<body>
<framework:msg />
<html:form action='<%=  (String)request.getAttribute(Constants.STRUTS_PATH) %>' method="post">
<html:hidden property="webMethod" />
<html:hidden property="id" />
<table width="95%">
<tr>
	<td align='right'>选中组：</td>
	<td colspan=2 align='left'><framework:attr source="adminGroupForm" attr="name" /></td>
</tr>
<tr>
	<td align='right'>未选中用户</td>
	<td align='left'></td>
	<td align='left'>选中用户</td>
</tr>
<tr>
	<td width="30%" align='right'>
		<framework:select name="avaiableUsers" dataSourceName="users" size="10" multiple="true" />
	</td>
	<td width="5%" valign='middle' align='center'>
		<input type='button' value='&nbsp;&gt;&nbsp;' onclick="add()">
		<input type='button' value='&gt;&gt;' onclick="addAll()">
		<input type='button' value='&nbsp;&lt;&nbsp;' onclick="remove()">
		<input type='button' value='&lt;&lt;' onclick="removeAll()">
	</td>
	<td width="*%">
		<framework:select name="selectedUser" dataSourceName="groupUsers" size="10" multiple="true" />
	</td>
</tr>
</table>
<framework:funcbtn operation='groupUser' submitFunction="submitTheForm" valueKey ="form.submit" />
<input type='reset' value='<bean:message key="form.reset" />'>
</html:form>
</body>
<script>
function submitTheForm(operation){
	var options = adminGroupForm.selectedUser.options;
	for(i=0;i<options.length; i++){
		options[i].selected=true;
	}
	submitForm(operation);
}

function add(){
	var options = adminGroupForm.avaiableUsers.options;
	var length = adminGroupForm.selectedUser.options.length;
	for(i=options.length - 1; i >= 0; i--){
		if(!options[i].selected) continue;
		var oOption = document.createElement("OPTION");
		adminGroupForm.selectedUser.options.add(oOption,length);
		oOption.innerText = options[i].innerText;
		oOption.Value = options[i].value;
		adminGroupForm.avaiableUsers.options.remove(i);
	}
}

function remove(){
	var options = adminGroupForm.selectedUser.options;
	var length = adminGroupForm.avaiableUsers.options.length;
	for(i=options.length - 1; i >= 0; i--){
		if(!options[i].selected) continue;
		var oOption = document.createElement("OPTION");
		adminGroupForm.avaiableUsers.options.add(oOption,length);
		oOption.innerText = options[i].innerText;
		oOption.Value = options[i].value;
		adminGroupForm.selectedUser.options.remove(i);
	}
}

function addAll(){
	var options = adminGroupForm.avaiableUsers.options;
	var length = adminGroupForm.selectedUser.options.length;
	for(i=options.length - 1; i >= 0; i--){
		var oOption = document.createElement("OPTION");
		oOption.innerText = options[i].innerText;
		oOption.Value = options[i].value;
		adminGroupForm.selectedUser.options.add(oOption,length);
		alert(oOption.value);
		adminGroupForm.avaiableUsers.options.remove(i);
	}
}
function removeAll(){
	var options = adminGroupForm.selectedUser.options;
	var length = adminGroupForm.avaiableUsers.options.length;
	for(i=options.length - 1; i >= 0; i--){
		var oOption = document.createElement("OPTION");
		oOption.innerText = options[i].innerText;
		oOption.Value = options[i].value;
		adminGroupForm.avaiableUsers.options.add(oOption,length);
		alert(oOption.value);
		adminGroupForm.selectedUser.options.remove(i);
	}
}
</script>
</html>